package com.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.entity.MPost;
import com.service.MPostService;
import com.vo.CommentVo;
import com.vo.PostVo;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

import com.controller.BaseController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 公众号：java思维导图
 * @since 2020-12-13
 */
@RestController
public class MPostController extends BaseController {

    @GetMapping("/post/{id:\\d*}")
    @ApiOperation("文章详情")
    public PostVo detail(@ApiParam("用户Id") @PathVariable(name = "id") Long id){
        PostVo postVo = postService.selectOnePost(id);
        Assert.notNull(postVo, "当前文章不存在或者已经被删除");

        //浏览量+1
        postService.putViewCount(postVo);

        IPage<CommentVo> commentVoIPage = commentService.paging(getPage(), postVo.getId(), null, "created");
        for (CommentVo comment:commentVoIPage.getRecords()) {
            System.out.println(comment);
        }
        return postVo;
    }

}
